package model

import (
	"gitee.com/xuxinzhi2206/corehub/database/mysql"
	"gorm.io/gorm"
)

type Points struct {
	gorm.Model
	UserId        int64  `gorm:"type:int(11);comment:用户id"`
	Username      string `gorm:"type:varchar(50);not null;comment:用户名称"`
	PointsBalance int64  `gorm:"type:int(11);comment:积分余额"`
}

func (p *Points) CreatePoints() error {
	return mysql.WithMysql(func(db *gorm.DB) error {
		return db.Create(&p).Error
	})
}
func (p *Points) GetPoints() (info []*Points, err error) {
	return info, mysql.WithMysql(func(db *gorm.DB) error {
		return db.Where("user_id =?", p.UserId).Find(&info).Error
	})
}
func (p *Points) UpdatePoints() (*Points, error) {
	return p, mysql.WithMysql(func(db *gorm.DB) error {
		return db.Model(p).Debug().Where("user_id = ?", p.UserId).Update("points_balance", p.PointsBalance).Error
	})
}
